<html>
    <head>
    <link rel="stylesheet" href="lmm.css" type="text/css" />
    </head>
<body class="lmm">
<!-- This file is part of the Lisp Machine manual.	-*-Text-*- -->
<!-- Macros: introduction, examples, DEFMACRO, backquote. -->
<!-- Note: there are still some sections to be written; see end of the file. -->

<div class='chapter' id='19'>19. Macros</div><p class='cindent' id='macro'><!-- macros -->
<!-- Macros!!!!!!! -->

<div class='section' id='19.1'>19.1 Introduction to Macros</div>
If <!-- open: 1, close: 0 --><font class="lisp">eval</font><!-- open: 1, close: 1 --> <!-- MATCHED MATCHED MATCHED --> is handed a list whose <!-- open: 2, close: 1 --><font class="italic">car</font><!-- open: 2, close: 2 --> <!-- MATCHED MATCHED MATCHED --> is a symbol, then <!-- open: 3, close: 2 --><font class="lisp">eval</font><!-- open: 3, close: 3 --> <!-- MATCHED MATCHED MATCHED -->
inspects the definition of the symbol to find out what to do.  If the
definition is a <!-- open: 4, close: 3 --><font class="italic">cons</font><!-- open: 4, close: 4 --> <!-- MATCHED MATCHED MATCHED -->, and the <!-- open: 5, close: 4 --><font class="italic">car</font><!-- open: 5, close: 5 --> <!-- MATCHED MATCHED MATCHED --> of the <!-- open: 6, close: 5 --><font class="italic">cons</font><!-- open: 6, close: 6 --> <!-- MATCHED MATCHED MATCHED --> is the symbol
<!-- open: 7, close: 6 --><font class="lisp">macro</font><!-- open: 7, close: 7 --> <!-- MATCHED MATCHED MATCHED -->, then the definition (i.e. that cons) is called a <!-- open: 8, close: 7 --><font class="italic">macro</font><!-- open: 8, close: 8 --> <!-- MATCHED MATCHED MATCHED -->.
The <!-- open: 9, close: 8 --><font class="italic">cdr</font><!-- open: 9, close: 9 --> <!-- MATCHED MATCHED MATCHED --> of the <!-- open: 10, close: 9 --><font class="italic">cons</font><!-- open: 10, close: 10 --> <!-- MATCHED MATCHED MATCHED --> should be a function of one argument.
<!-- open: 11, close: 10 --><font class="lisp">eval</font><!-- open: 11, close: 11 --> <!-- MATCHED MATCHED MATCHED --> applies the function to the form it was originally given.
Then it takes whatever is returned, and evaluates that in lieu of the
original form.

	Here is a simple example.  Suppose the definition of the symbol <!-- open: 12, close: 11 --><font class="lisp">first</font><!-- open: 12, close: 12 --> <!-- MATCHED MATCHED MATCHED --> is
<pre class='lisp'>
(macro lambda (x) 
         (list 'car (cadr x)))
</pre>
This thing is a macro: it is a <!-- open: 13, close: 12 --><font class="italic">cons</font><!-- open: 13, close: 13 --> <!-- MATCHED MATCHED MATCHED --> whose <!-- open: 14, close: 13 --><font class="italic">car</font><!-- open: 14, close: 14 --> <!-- MATCHED MATCHED MATCHED --> is the symbol <!-- open: 15, close: 14 --><font class="lisp">macro</font><!-- open: 15, close: 15 --> <!-- MATCHED MATCHED MATCHED -->.
What happens if we try to evaluate a form <!-- open: 16, close: 15 --><font class="lisp">(first '(a b c))</font><!-- open: 16, close: 16 --> <!-- MATCHED MATCHED MATCHED -->?  Well,
<!-- open: 17, close: 16 --><font class="lisp">eval</font><!-- open: 17, close: 17 --> <!-- MATCHED MATCHED MATCHED --> sees that it has a list whose <!-- open: 18, close: 17 --><font class="italic">car</font><!-- open: 18, close: 18 --> <!-- MATCHED MATCHED MATCHED --> is a symbol (namely,
<!-- open: 19, close: 18 --><font class="lisp">first</font><!-- open: 19, close: 19 --> <!-- MATCHED MATCHED MATCHED -->), so it looks at the definition of the symbol and sees that
it is a <!-- open: 20, close: 19 --><font class="italic">cons</font><!-- open: 20, close: 20 --> <!-- MATCHED MATCHED MATCHED --> whose <!-- open: 21, close: 20 --><font class="italic">car</font><!-- open: 21, close: 21 --> <!-- MATCHED MATCHED MATCHED --> is <!-- open: 22, close: 21 --><font class="lisp">macro</font><!-- open: 22, close: 22 --> <!-- MATCHED MATCHED MATCHED -->; the definition is a macro.
<!-- open: 23, close: 22 --><font class="lisp">eval</font><!-- open: 23, close: 23 --> <!-- MATCHED MATCHED MATCHED --> takes the <!-- open: 24, close: 23 --><font class="italic">cdr</font><!-- open: 24, close: 24 --> <!-- MATCHED MATCHED MATCHED --> of the cons,
which is a lambda expression, and <!-- open: 25, close: 24 --><font class="italic">applies</font><!-- open: 25, close: 25 --> <!-- MATCHED MATCHED MATCHED --> it to the
original form that <!-- open: 26, close: 25 --><font class="lisp">eval</font><!-- open: 26, close: 26 --> <!-- MATCHED MATCHED MATCHED --> was handed.
So it applies <!-- open: 27, close: 26 --><font class="lisp">(lambda (x) (list 'car (cadr x)))</font><!-- open: 27, close: 27 --> <!-- MATCHED MATCHED MATCHED -->
to <!-- open: 28, close: 27 --><font class="lisp">(first '(a b c))</font><!-- open: 28, close: 28 --> <!-- MATCHED MATCHED MATCHED -->.  <!-- open: 29, close: 28 --><font class="lisp">x</font><!-- open: 29, close: 29 --> <!-- MATCHED MATCHED MATCHED --> is bound to <!-- open: 30, close: 29 --><font class="lisp">(first '(a b c))</font><!-- open: 30, close: 30 --> <!-- MATCHED MATCHED MATCHED -->,
<!-- open: 31, close: 30 --><font class="lisp">(cadr x)</font><!-- open: 31, close: 31 --> <!-- MATCHED MATCHED MATCHED --> evaluates to <!-- open: 32, close: 31 --><font class="lisp">'(a b c)</font><!-- open: 32, close: 32 --> <!-- MATCHED MATCHED MATCHED -->, and <!-- open: 33, close: 32 --><font class="lisp">(list 'car (cadr x))</font><!-- open: 33, close: 33 --> <!-- MATCHED MATCHED MATCHED -->
evaluates to <!-- open: 34, close: 33 --><font class="lisp">(car '(a b c))</font><!-- open: 34, close: 34 --> <!-- MATCHED MATCHED MATCHED -->, which is what the function returns.
<!-- open: 35, close: 34 --><font class="lisp">eval</font><!-- open: 35, close: 35 --> <!-- MATCHED MATCHED MATCHED --> now evaluates this new form in place of the original form.
<!-- open: 36, close: 35 --><font class="lisp">(car '(a b c))</font><!-- open: 36, close: 36 --> <!-- MATCHED MATCHED MATCHED --> returns <!-- open: 37, close: 36 --><font class="lisp">a</font><!-- open: 37, close: 37 --> <!-- MATCHED MATCHED MATCHED -->, and so the result is that
<!-- open: 38, close: 37 --><font class="lisp">(first '(a b c))</font><!-- open: 38, close: 38 --> <!-- MATCHED MATCHED MATCHED --> returns <!-- open: 39, close: 38 --><font class="lisp">a</font><!-- open: 39, close: 39 --> <!-- MATCHED MATCHED MATCHED -->.

	What have we done?  We have defined a macro called <!-- open: 40, close: 39 --><font class="lisp">first</font><!-- open: 40, close: 40 --> <!-- MATCHED MATCHED MATCHED -->.  What
the macro does is to <!-- open: 41, close: 40 --><font class="italic">translate</font><!-- open: 41, close: 41 --> <!-- MATCHED MATCHED MATCHED --> the form to some other form.  Our
translation is very simple--it just translates forms that look like
<!-- open: 42, close: 41 --><font class="lisp">(first <!-- open: 43, close: 41 --><font class="italic">x</font><!-- open: 43, close: 42 -->)</font><!-- open: 43, close: 43 --> <!-- MATCHED MATCHED MATCHED --> into <!-- open: 44, close: 43 --><font class="lisp">(car <!-- open: 45, close: 43 --><font class="italic">x</font><!-- open: 45, close: 44 -->)</font><!-- open: 45, close: 45 --> <!-- MATCHED MATCHED MATCHED -->, for any form <!-- open: 46, close: 45 --><font class="italic">x</font><!-- open: 46, close: 46 --> <!-- MATCHED MATCHED MATCHED -->.
We can do much more
interesting things with macros, but first we will show how
to define a macro.

	Macros are normally defined using the <!-- open: 47, close: 46 --><font class="lisp">macro</font><!-- open: 47, close: 47 --> <!-- MATCHED MATCHED MATCHED --> special form.
A macro definition looks like this:
<pre class='lisp'>
(macro <!-- open: 48, close: 47 --><font class="italic">name</font><!-- open: 48, close: 48 --> <!-- MATCHED MATCHED MATCHED --> (<!-- open: 49, close: 48 --><font class="italic">arg</font><!-- open: 49, close: 49 --> <!-- MATCHED MATCHED MATCHED -->)
    <!-- open: 50, close: 49 --><font class="italic">body</font><!-- open: 50, close: 50 --> <!-- MATCHED MATCHED MATCHED -->)
</pre>
To define our <!-- open: 51, close: 50 --><font class="lisp">first</font><!-- open: 51, close: 51 --> <!-- MATCHED MATCHED MATCHED --> macro, we would say
<pre class='lisp'>
(macro first (x)
    (list 'car (cadr x)))
</pre>

	Here are some more simple examples of macros.  Suppose we want
any form that looks like <!-- open: 52, close: 51 --><font class="lisp">(addone <!-- open: 53, close: 51 --><font class="italic">x</font><!-- open: 53, close: 52 -->)</font><!-- open: 53, close: 53 --> <!-- MATCHED MATCHED MATCHED --> to be translated into
<!-- open: 54, close: 53 --><font class="lisp">(plus 1 <!-- open: 55, close: 53 --><font class="italic">x</font><!-- open: 55, close: 54 -->)</font><!-- open: 55, close: 55 --> <!-- MATCHED MATCHED MATCHED -->.  To define a macro to do this we would say
<pre class='lisp'>
(macro addone (x)
   (list 'plus '1 (cadr x)))
</pre>

	Now say we wanted a macro which would translate <!-- open: 56, close: 55 --><font class="lisp">(increment <!-- open: 57, close: 55 --><font class="italic">x</font><!-- open: 57, close: 56 -->)</font><!-- open: 57, close: 57 --> <!-- MATCHED MATCHED MATCHED -->
into <!-- open: 58, close: 57 --><font class="lisp">(setq <!-- open: 59, close: 57 --><font class="italic">x</font><!-- open: 59, close: 58 --> (1+ <!-- open: 60, close: 58 --><font class="italic">x</font><!-- open: 60, close: 59 -->)</font><!-- open: 60, close: 60 --> <!-- MATCHED MATCHED MATCHED -->.  This would be:
<pre class='lisp'>
(macro increment (x)
    (list 'setq (cadr x) (list '1+ (cadr x))))
</pre>
Of course, this macro is of limited usefulness.  The reason is that the
form in the <!-- open: 61, close: 60 --><font class="italic">cadr</font><!-- open: 61, close: 61 --> <!-- MATCHED MATCHED MATCHED --> of the <!-- open: 62, close: 61 --><font class="lisp">increment</font><!-- open: 62, close: 62 --> <!-- MATCHED MATCHED MATCHED --> form had better be a symbol.
If you tried <!-- open: 63, close: 62 --><font class="lisp">(increment (car x))</font><!-- open: 63, close: 63 --> <!-- MATCHED MATCHED MATCHED -->, it would be translated into
<!-- open: 64, close: 63 --><font class="lisp">(setq (car x) (1+ (car x)))</font><!-- open: 64, close: 64 --> <!-- MATCHED MATCHED MATCHED -->, and <!-- open: 65, close: 64 --><font class="lisp">setq</font><!-- open: 65, close: 65 --> <!-- MATCHED MATCHED MATCHED --> would complain.

	You can see from this discussion that macros are very different
from functions.  A function would not be able to tell what kind of subforms
are around in a call to itself; they get evaluated before the functions
ever sees them.  However, a macro gets to look at the whole form and see
just what is going on there.  Macros are <!-- open: 66, close: 65 --><font class="italic">not</font><!-- open: 66, close: 66 --> <!-- MATCHED MATCHED MATCHED --> functions; if <!-- open: 67, close: 66 --><font class="lisp">first</font><!-- open: 67, close: 67 --> <!-- MATCHED MATCHED MATCHED -->
is defined as a macro, it is not meaningful to apply <!-- open: 68, close: 67 --><font class="lisp">first</font><!-- open: 68, close: 68 --> <!-- MATCHED MATCHED MATCHED --> to arguments.
A macro does not take arguments at all; it takes a <!-- open: 69, close: 68 --><font class="italic">Lisp form</font><!-- open: 69, close: 69 --> <!-- MATCHED MATCHED MATCHED --> and turns
it into another <!-- open: 70, close: 69 --><font class="italic">Lisp form</font><!-- open: 70, close: 70 --> <!-- MATCHED MATCHED MATCHED -->.

	The purpose of functions is to <!-- open: 71, close: 70 --><font class="italic">compute</font><!-- open: 71, close: 71 --> <!-- MATCHED MATCHED MATCHED -->; the purpose of
macros is to <!-- open: 72, close: 71 --><font class="italic">translate</font><!-- open: 72, close: 72 --> <!-- MATCHED MATCHED MATCHED -->.  Macros are used for a variety of purposes, the
most common being extensions to the Lisp language.  For example, Lisp
is powerful enough to express many different control structures, but it
does not provide every control structure anyone might ever possibly
want.  Instead, if a user wants some kind of control structure with a
syntax that is not provided, he can  translate it into some form that
Lisp <!-- open: 73, close: 72 --><font class="italic">does</font><!-- open: 73, close: 73 --> <!-- MATCHED MATCHED MATCHED --> know about.

	For example, someone might want a limited iteration construct
which increments a symbol by one until it exceeds a limit (like the
FOR statement of the BASIC language).  He might want it to look like
<pre class='lisp'>
(for a 1 100 (print a) (print (* a a)))
</pre>
To get this, he could write a macro to translate it into
<pre class='lisp'>
(do a 1 (1+ a) (&gt; a 100) (print a) (print (* a a)))
</pre>
A macro to do this could be defined with
<pre class='lisp'>
(macro for (x)
  (cons 'do
	(cons (cadr x)
	      (cons (caddr x)
		    (cons (list '1+ (cadr x))
			  (cons (list '&gt; (cadr x) (cadddr x))
				(cddddr x)))))))
</pre>
Now he has defined his own new control structure primitive, and it
will act just as if it were a special form provided by Lisp itself.

<div class='section' id='19.2'>19.2 Aids for Defining Macros</div>
	The main problem with the definition for the <!-- open: 74, close: 73 --><font class="lisp">for</font><!-- open: 74, close: 74 --> <!-- MATCHED MATCHED MATCHED --> macro is
that it is verbose and clumsy.  If it is that hard to write a macro
to do a simple specialized iteration construct, one would wonder how
anyone would write macros of any real sophistication.

	There are two things that make the definition so inelegant.
One is that the programmer must write things like "<!-- open: 75, close: 74 --><font class="lisp">(cadr x)</font><!-- open: 75, close: 75 --> <!-- MATCHED MATCHED MATCHED -->"
and "<!-- open: 76, close: 75 --><font class="lisp">(cddddr x)</font><!-- open: 76, close: 76 --> <!-- MATCHED MATCHED MATCHED -->" to refer to the parts of the form he wants
to do things with.  The other problem is that the long chains of calls
to the <!-- open: 77, close: 76 --><font class="lisp">list</font><!-- open: 77, close: 77 --> <!-- MATCHED MATCHED MATCHED --> and <!-- open: 78, close: 77 --><font class="lisp">cons</font><!-- open: 78, close: 78 --> <!-- MATCHED MATCHED MATCHED --> functions are very hard to read.

	Two features are provided to solve these two problems.
The <!-- open: 79, close: 78 --><font class="lisp">defmacro</font><!-- open: 79, close: 79 --> <!-- MATCHED MATCHED MATCHED --> macro solves the former, and the "backquote" ("<!-- open: 80, close: 79 --><font class="lisp">&thinsp;`&thinsp;</font><!-- open: 80, close: 80 --> <!-- MATCHED MATCHED MATCHED -->")
reader macro solves the latter.

<div class='subsection id='19.2.1''>19.2.1 Defmacro</div><p class='cindent'><!-- macro-defining macros -->

	Instead of referring to the parts of our form by "<!-- open: 81, close: 80 --><font class="lisp">(cadr x)</font><!-- open: 81, close: 81 --> <!-- MATCHED MATCHED MATCHED -->"
and such, we would like to give names to the various pieces of the form,
and somehow have the <!-- open: 82, close: 81 --><font class="lisp">(cadr x)</font><!-- open: 82, close: 82 --> <!-- MATCHED MATCHED MATCHED --> automatically generated.  This is done
by a macro called <!-- open: 83, close: 82 --><font class="lisp">defmacro</font><!-- open: 83, close: 83 --> <!-- MATCHED MATCHED MATCHED -->.  It is easiest to explain what <!-- open: 84, close: 83 --><font class="lisp">defmacro</font><!-- open: 84, close: 84 --> <!-- MATCHED MATCHED MATCHED --> does
by showing an example. Here is how you would write the <!-- open: 85, close: 84 --><font class="lisp">for</font><!-- open: 85, close: 85 --> <!-- MATCHED MATCHED MATCHED --> macro
using <!-- open: 86, close: 85 --><font class="lisp">defmacro</font><!-- open: 86, close: 86 --> <!-- MATCHED MATCHED MATCHED -->:
<pre class='lisp'>
(defmacro for (var lower upper . body)
  (cons 'do
	(cons var
	      (cons lower
		    (cons (list '1+ var)
			  (cons (list '&gt; var upper)
				body))))))
</pre>

	The <!-- open: 87, close: 86 --><font class="lisp">(var lower upper . body)</font><!-- open: 87, close: 87 --> <!-- MATCHED MATCHED MATCHED --> is a <!-- open: 88, close: 87 --><font class="italic">pattern</font><!-- open: 88, close: 88 --> <!-- MATCHED MATCHED MATCHED --> to match against
the body of the macro (to be more precise, to match against the <!-- open: 89, close: 88 --><font class="italic">cdr</font><!-- open: 89, close: 89 --> <!-- MATCHED MATCHED MATCHED -->
of the argument to the macro).  <!-- open: 90, close: 89 --><font class="lisp">defmacro</font><!-- open: 90, close: 90 --> <!-- MATCHED MATCHED MATCHED --> tries to match the two
lists
<pre class='lisp'>
(var lower upper . body)
<!-- open: 91, close: 90 --><font class="main">and</font><!-- open: 91, close: 91 --> <!-- MATCHED MATCHED MATCHED -->
(a 1 100 (print a) (print (* a a)))
</pre>
<!-- open: 92, close: 91 --><font class="lisp">var</font><!-- open: 92, close: 92 --> <!-- MATCHED MATCHED MATCHED --> will get bound to the symbol <!-- open: 93, close: 92 --><font class="lisp">a</font><!-- open: 93, close: 93 --> <!-- MATCHED MATCHED MATCHED -->, <!-- open: 94, close: 93 --><font class="lisp">lower</font><!-- open: 94, close: 94 --> <!-- MATCHED MATCHED MATCHED --> to the fixnum <!-- open: 95, close: 94 --><font class="lisp">1</font><!-- open: 95, close: 95 --> <!-- MATCHED MATCHED MATCHED -->,
<!-- open: 96, close: 95 --><font class="lisp">upper</font><!-- open: 96, close: 96 --> <!-- MATCHED MATCHED MATCHED --> to the fixnum <!-- open: 97, close: 96 --><font class="lisp">100</font><!-- open: 97, close: 97 --> <!-- MATCHED MATCHED MATCHED -->, and <!-- open: 98, close: 97 --><font class="lisp">body</font><!-- open: 98, close: 98 --> <!-- MATCHED MATCHED MATCHED --> to the list
<!-- open: 99, close: 98 --><font class="lisp">((print a) (print (* a a)))</font><!-- open: 99, close: 99 --> <!-- MATCHED MATCHED MATCHED -->.  Then inside the body of the <!-- open: 100, close: 99 --><font class="lisp">defmacro</font><!-- open: 100, close: 100 --> <!-- MATCHED MATCHED MATCHED -->,
<!-- open: 101, close: 100 --><font class="lisp">var, lower, upper,</font><!-- open: 101, close: 101 --> <!-- MATCHED MATCHED MATCHED --> and <!-- open: 102, close: 101 --><font class="lisp">body</font><!-- open: 102, close: 102 --> <!-- MATCHED MATCHED MATCHED --> are variables, bound to the matching
parts of the macro form.

<div class='defmac' id='defmacro'><font class='exdent'><font class='funcname' id='defmacro'>defmacro</font><font class="italic"> Macro</font></br></font><!-- end font_exdent --><!-- open: 103, close: 102 --><font class="lisp">defmacro</font><!-- open: 103, close: 103 --> <!-- MATCHED MATCHED MATCHED --> is a general purpose macro-defining macro.  A <!-- open: 104, close: 103 --><font class="lisp">defmacro</font><!-- open: 104, close: 104 --> <!-- MATCHED MATCHED MATCHED -->
form looks like 
<pre class='lisp'>
(defmacro <!-- open: 105, close: 104 --><font class="italic">name</font><!-- open: 105, close: 105 --> <!-- MATCHED MATCHED MATCHED --> <!-- open: 106, close: 105 --><font class="italic">pattern</font><!-- open: 106, close: 106 --> <!-- MATCHED MATCHED MATCHED --> . <!-- open: 107, close: 106 --><font class="italic">body</font><!-- open: 107, close: 107 --> <!-- MATCHED MATCHED MATCHED -->)
</pre>
The <!-- open: 108, close: 107 --><font class="italic">pattern</font><!-- open: 108, close: 108 --> <!-- MATCHED MATCHED MATCHED --> may be anything made up out of symbols and conses.
It is matched against the body of the macro form; both <!-- open: 109, close: 108 --><font class="italic">pattern</font><!-- open: 109, close: 109 --> <!-- MATCHED MATCHED MATCHED -->
and the form are <!-- open: 110, close: 109 --><font class="italic">car</font><!-- open: 110, close: 110 --> <!-- MATCHED MATCHED MATCHED -->'ed and <!-- open: 111, close: 110 --><font class="italic">cdr</font><!-- open: 111, close: 111 --> <!-- MATCHED MATCHED MATCHED -->'ed identically, and whenever
a symbol is hit in <!-- open: 112, close: 111 --><font class="italic">pattern</font><!-- open: 112, close: 112 --> <!-- MATCHED MATCHED MATCHED -->, the symbol is bound to the corresponding
part of the form.  All of the symbols in <!-- open: 113, close: 112 --><font class="italic">pattern</font><!-- open: 113, close: 113 --> <!-- MATCHED MATCHED MATCHED --> can be used
as variables within <!-- open: 114, close: 113 --><font class="italic">body</font><!-- open: 114, close: 114 --> <!-- MATCHED MATCHED MATCHED -->.  <!-- open: 115, close: 114 --><font class="italic">name</font><!-- open: 115, close: 115 --> <!-- MATCHED MATCHED MATCHED --> is the name of the macro
to be defined.  <!-- open: 116, close: 115 --><font class="italic">body</font><!-- open: 116, close: 116 --> <!-- MATCHED MATCHED MATCHED --> is evaluated with these bindings in effect,
and is returned to the evaluator.
</div>

	Note that the pattern need not be a list the way a lambda-list must.
In the above example, the pattern was a "dotted list", since the symbol
<!-- open: 117, close: 116 --><font class="lisp">body</font><!-- open: 117, close: 117 --> <!-- MATCHED MATCHED MATCHED --> was supposed to match the <!-- open: 118, close: 117 --><font class="italic">cddddr</font><!-- open: 118, close: 118 --> <!-- MATCHED MATCHED MATCHED --> of the macro form.
If we wanted a new iteration form, like <!-- open: 119, close: 118 --><font class="lisp">for</font><!-- open: 119, close: 119 --> <!-- MATCHED MATCHED MATCHED --> except that it
our example would look like
<pre class='lisp'>
(for a (1 100) (print a) (print (* a a)))
</pre>
(just because we thought that was a nicer syntax), then we could
do it merely by modifying the pattern of the <!-- open: 120, close: 119 --><font class="lisp">defmacro</font><!-- open: 120, close: 120 --> <!-- MATCHED MATCHED MATCHED --> above;
the new pattern would be <!-- open: 121, close: 120 --><font class="lisp">(var (lower upper) . body)</font><!-- open: 121, close: 121 --> <!-- MATCHED MATCHED MATCHED -->.

	Here is how we would write our other examples using <!-- open: 122, close: 121 --><font class="lisp">defmacro</font><!-- open: 122, close: 122 --> <!-- MATCHED MATCHED MATCHED -->:
<pre class='lisp'>
(defmacro first (the-list)
    (list 'car the-list))

(defmacro addone (form)
   (list 'plus '1 form))

(defmacro increment (symbol)
   (list 'setq symbol (list '1+ symbol)))
</pre>
All of these were very simple macros and have very simple patterns,
but these examples show that we can replace the <!-- open: 123, close: 122 --><font class="lisp">(cadr x)</font><!-- open: 123, close: 123 --> <!-- MATCHED MATCHED MATCHED --> with a
readable mnemonic name such as <!-- open: 124, close: 123 --><font class="lisp">the-list</font><!-- open: 124, close: 124 --> <!-- MATCHED MATCHED MATCHED --> or <!-- open: 125, close: 124 --><font class="lisp">symbol</font><!-- open: 125, close: 125 --> <!-- MATCHED MATCHED MATCHED -->, which
makes the program clearer.

	There is another version of <!-- open: 126, close: 125 --><font class="lisp">defmacro</font><!-- open: 126, close: 126 --> <!-- MATCHED MATCHED MATCHED --> which defines
displacing macros (see <font color='red'>LINK:(</font>displacing-macro)).
<!-- open: 127, close: 126 --><font class="lisp">defmacro</font><!-- open: 127, close: 127 --> <!-- MATCHED MATCHED MATCHED --> has other, more complex features; see <font color='red'>LINK:(</font>defmacro-hair).

<div class='subsection id='19.2.2''>19.2.2 Backquote</div>
	Now we deal with the other problem: the long strings of calls
to <!-- open: 128, close: 127 --><font class="lisp">cons</font><!-- open: 128, close: 128 --> <!-- MATCHED MATCHED MATCHED --> and <!-- open: 129, close: 128 --><font class="lisp">list</font><!-- open: 129, close: 129 --> <!-- MATCHED MATCHED MATCHED -->.  For this we must introduce some <!-- open: 130, close: 129 --><font class="italic">reader
macros</font><!-- open: 130, close: 130 --> <!-- MATCHED MATCHED MATCHED -->.  Reader macros are not the same as normal macros, and they
are not described in this chapter; see <font color='red'>LINK:(</font>reader).

	The backquote facility is used by giving a backquote character ("<!-- open: 131, close: 130 --><font class="lisp">&larr;`</font><!-- open: 131, close: 131 --> <!-- MATCHED MATCHED MATCHED -->",
ASCII code 140 octal), followed by a form.  If the form does not contain
any use of the comma macro-character, the form will simply be quoted.  For example,
<pre class='lisp'>
 '(a b c) ==&gt; (a b c)
 `(a b c) ==&gt; (a b c)
</pre>
So in the simple cases, backquote is just like the regular single-quote
macro.  The way to get it to do interesting things is to include a use
of the comma somewhere inside of the form following the backquote.
The comma is followed by a form, and that form gets evaluated even
though it is inside the backquote.  For example,
<pre class='lisp'>
(setq b 1)
`(a b c)  ==&gt; (a b c)
`(a ,b c) ==&gt; (a 1 c)
</pre>
In other words, backquote quotes everything <!-- open: 132, close: 131 --><font class="italic">except</font><!-- open: 132, close: 132 --> <!-- MATCHED MATCHED MATCHED --> things preceeded by
a comma; those things get evaluated.

	When the reader sees the <!-- open: 133, close: 132 --><font class="lisp">`(a ,b c)</font><!-- open: 133, close: 133 --> <!-- MATCHED MATCHED MATCHED --> it is actually generating
a form such as <!-- open: 134, close: 133 --><font class="lisp">(list 'a b 'c)</font><!-- open: 134, close: 134 --> <!-- MATCHED MATCHED MATCHED -->.  The actual form generated may use <!-- open: 135, close: 134 --><font class="lisp">list</font><!-- open: 135, close: 135 --> <!-- MATCHED MATCHED MATCHED -->,
<!-- open: 136, close: 135 --><font class="lisp">cons</font><!-- open: 136, close: 136 --> <!-- MATCHED MATCHED MATCHED -->, <!-- open: 137, close: 136 --><font class="lisp">append</font><!-- open: 137, close: 137 --> <!-- MATCHED MATCHED MATCHED -->, or whatever might be a good idea; you should
never have to concern yourself with what it actually turns into.  All you
need to care about is what it evaluates to.

	This is generally found to be pretty confusing by most people; the best way
to explain further seems to be with examples.  Here is how we would write our
three simple macros using both the <!-- open: 138, close: 137 --><font class="lisp">defmacro</font><!-- open: 138, close: 138 --> <!-- MATCHED MATCHED MATCHED --> and backquote facilities.
<pre class='lisp'>
(defmacro first (the-list)
    `(car ,the-list))

(defmacro addone (form)
   `(plus 1 ,form))

(defmacro increment (symbol)
   `(setq ,symbol (1+ ,symbol)))
</pre>
To finally demonstrate how easy it is to define macros with these two facilities,
here is the final form of the <!-- open: 139, close: 138 --><font class="lisp">for</font><!-- open: 139, close: 139 --> <!-- MATCHED MATCHED MATCHED --> macro.
<pre class='lisp'>
(defmacro for (var lower upper . body)
  `(do ,var ,lower (1+ ,var) (&gt; ,var ,upper) . ,body))
</pre>
Look at how much simpler that is than the original definition.  Also,
look how closely it resembles the code it is producing.  The functionality
of the <!-- open: 140, close: 139 --><font class="lisp">for</font><!-- open: 140, close: 140 --> <!-- MATCHED MATCHED MATCHED --> really stands right out when written this way.

.C New part starts here.

	If a comma inside a backquote form is followed by an "atsign"
character ("<!-- open: 141, close: 140 --><font class="lisp"><u><font color='green'>SAIL</font></u>@</font><!-- open: 141, close: 141 --> <!-- MATCHED MATCHED MATCHED -->"), it has a special meaning.  The "<!-- open: 142, close: 141 --><font class="lisp"><u><font color='green'>SAIL</font></u>,<u><font color='green'>SAIL</font></u>@</font><!-- open: 142, close: 142 --> <!-- MATCHED MATCHED MATCHED -->" should
be followed by a form whose value is a <!-- open: 143, close: 142 --><font class="italic">list</font><!-- open: 143, close: 143 --> <!-- MATCHED MATCHED MATCHED -->; then each of the elements
of the list are put into the list being created by the backquote.  In other
words, instead of generating a call to the <!-- open: 144, close: 143 --><font class="lisp">cons</font><!-- open: 144, close: 144 --> <!-- MATCHED MATCHED MATCHED --> function, backquote
generates a call to <!-- open: 145, close: 144 --><font class="lisp">append</font><!-- open: 145, close: 145 --> <!-- MATCHED MATCHED MATCHED -->.  For example, if <!-- open: 146, close: 145 --><font class="lisp">a</font><!-- open: 146, close: 146 --> <!-- MATCHED MATCHED MATCHED --> is bound to
<!-- open: 147, close: 146 --><font class="lisp">(x y z)</font><!-- open: 147, close: 147 --> <!-- MATCHED MATCHED MATCHED -->, then <!-- open: 148, close: 147 --><font class="lisp">`(1 ,a 2)</font><!-- open: 148, close: 148 --> <!-- MATCHED MATCHED MATCHED --> would evaluate to <!-- open: 149, close: 148 --><font class="lisp">(1 (x y z) 2)</font><!-- open: 149, close: 149 --> <!-- MATCHED MATCHED MATCHED -->,
but <!-- open: 150, close: 149 --><font class="lisp">`(1 ,@a 2)</font><!-- open: 150, close: 150 --> <!-- MATCHED MATCHED MATCHED --> would evaluate to <!-- open: 151, close: 150 --><font class="lisp">`(1 x y z 2)</font><!-- open: 151, close: 151 --> <!-- MATCHED MATCHED MATCHED -->.

	Here is an example of a macro definition that uses the "<!-- open: 152, close: 151 --><font class="lisp"><u><font color='green'>SAIL</font></u>,<u><font color='green'>SAIL</font></u>@</font><!-- open: 152, close: 152 --> <!-- MATCHED MATCHED MATCHED -->"
construction.  Suppose you wanted to extend Lisp by adding a kind of
special form called <!-- open: 153, close: 152 --><font class="lisp">repeat-forever</font><!-- open: 153, close: 153 --> <!-- MATCHED MATCHED MATCHED -->, which evaluates all of its
subforms repeatedly.  One way to implement this would be to expand
<pre class='lisp'>
(repeat-forever <!-- open: 154, close: 153 --><font class="italic">form1</font><!-- open: 154, close: 154 --> <!-- MATCHED MATCHED MATCHED --> <!-- open: 155, close: 154 --><font class="italic">form2</font><!-- open: 155, close: 155 --> <!-- MATCHED MATCHED MATCHED --> <!-- open: 156, close: 155 --><font class="italic">form3</font><!-- open: 156, close: 156 --> <!-- MATCHED MATCHED MATCHED -->)
</pre>
into
<pre class='lisp'>
(prog ()
    a <!-- open: 157, close: 156 --><font class="italic">form1</font><!-- open: 157, close: 157 --> <!-- MATCHED MATCHED MATCHED -->
      <!-- open: 158, close: 157 --><font class="italic">form2</font><!-- open: 158, close: 158 --> <!-- MATCHED MATCHED MATCHED -->
      <!-- open: 159, close: 158 --><font class="italic">form3</font><!-- open: 159, close: 159 --> <!-- MATCHED MATCHED MATCHED -->
      (go a))
</pre>
	You could define the macro by
<pre class='lisp'>
(macro repeat-forever body
       `(prog ()
            a ,@body
              (go a)))
</pre>

	Advanced macro writers sometimes write "macro-defining macros":
forms which expand into forms which, when evaluated, define macros.  In
such macros it is often useful to use nested backquote constructs.  The
following example illustrates the use of nested backquotes in the
writing of macro-defining macros.

	This example is a very simple version of <!-- open: 160, close: 159 --><font class="lisp">defstruct</font><!-- open: 160, close: 160 --> <!-- MATCHED MATCHED MATCHED --> (see <font color='red'>LINK:(</font>defstruct-fun)).
You should first understand the basic description of <!-- open: 161, close: 160 --><font class="lisp">defstruct</font><!-- open: 161, close: 161 --> <!-- MATCHED MATCHED MATCHED --> before
proceeding with this example.  The <!-- open: 162, close: 161 --><font class="lisp">defstruct</font><!-- open: 162, close: 162 --> <!-- MATCHED MATCHED MATCHED --> below does not accept
any options, and only allows the simplest kind of items; that is, it only
allows forms like
<pre class='lisp'>
(defstruct (<!-- open: 163, close: 162 --><font class="italic">name</font><!-- open: 163, close: 163 --> <!-- MATCHED MATCHED MATCHED -->)
     <!-- open: 164, close: 163 --><font class="italic">item1</font><!-- open: 164, close: 164 --> <!-- MATCHED MATCHED MATCHED -->
     <!-- open: 165, close: 164 --><font class="italic">item2</font><!-- open: 165, close: 165 --> <!-- MATCHED MATCHED MATCHED -->
     <!-- open: 166, close: 165 --><font class="italic">item3</font><!-- open: 166, close: 166 --> <!-- MATCHED MATCHED MATCHED -->
     <!-- open: 167, close: 166 --><font class="italic">item4</font><!-- open: 167, close: 167 --> <!-- MATCHED MATCHED MATCHED -->
     ...)
</pre>
	We would like this form to expand into
<pre class='lisp'>
(progn
 (defmacro <!-- open: 168, close: 167 --><font class="italic">item1</font><!-- open: 168, close: 168 --> <!-- MATCHED MATCHED MATCHED --> (x)
      `(aref ,x 1))
 (defmacro <!-- open: 169, close: 168 --><font class="italic">item2</font><!-- open: 169, close: 169 --> <!-- MATCHED MATCHED MATCHED --> (x)
      `(aref ,x 2))
 (defmacro <!-- open: 170, close: 169 --><font class="italic">item3</font><!-- open: 170, close: 170 --> <!-- MATCHED MATCHED MATCHED --> (x)
      `(aref ,x 3))
 (defmacro <!-- open: 171, close: 170 --><font class="italic">item4</font><!-- open: 171, close: 171 --> <!-- MATCHED MATCHED MATCHED --> (x)
      `(aref ,x 4))
 ...)
</pre>
	Here is the macro to perform the expansion:
<pre class='lisp'>
(defmacro defstruct ((name) . items)
     (do ((item-list items (cdr item-list))
	  (ans nil)
	  (i 0 (1+ i)))
	 ((null item-list)
          (cons 'progn (nreverse ans)))
       (setq ans
	     (cons `(defmacro ,(car item-list) (x)
			   `(aref ,x ,',i))
		   ans))))
</pre>
	The interesting part of this definition is the body of
the (inner) <!-- open: 172, close: 171 --><font class="lisp">defmacro</font><!-- open: 172, close: 172 --> <!-- MATCHED MATCHED MATCHED --> form: <!-- open: 173, close: 172 --><font class="lisp">`(aref ,x ,',i)</font><!-- open: 173, close: 173 --> <!-- MATCHED MATCHED MATCHED -->.
Instead of using this backquote construction, we could have
written <!-- open: 174, close: 173 --><font class="lisp">(list 'aref x ,i)</font><!-- open: 174, close: 174 --> <!-- MATCHED MATCHED MATCHED -->; that is, the "<!-- open: 175, close: 174 --><font class="lisp">,',</font><!-- open: 175, close: 175 --> <!-- MATCHED MATCHED MATCHED -->"
acts like a comma which matches the outer backquote, while
the "<!-- open: 176, close: 175 --><font class="lisp">,</font><!-- open: 176, close: 176 --> <!-- MATCHED MATCHED MATCHED -->" preceeding the "<!-- open: 177, close: 176 --><font class="lisp">x</font><!-- open: 177, close: 177 --> <!-- MATCHED MATCHED MATCHED -->" matches with the inner
backquote.  Thus, the symbol <!-- open: 178, close: 177 --><font class="lisp">i</font><!-- open: 178, close: 178 --> <!-- MATCHED MATCHED MATCHED --> is evaluated when the
<!-- open: 179, close: 178 --><font class="lisp">defstruct</font><!-- open: 179, close: 179 --> <!-- MATCHED MATCHED MATCHED --> form is expanded, whereas the symbol <!-- open: 180, close: 179 --><font class="lisp">x</font><!-- open: 180, close: 180 --> <!-- MATCHED MATCHED MATCHED --> is
evaluated when the accessor macros are expanded.

	Backquote can be useful in situations other than the writing
of macros.  Whenever there is a piece of list structure to be consed
up, most of which is constant, the use of backquote can make the
program considerably clearer.

<div class='section' id='19.3'>19.3 Aids for Debugging Macros</div>
<div class='defun' id='mexp'>
  <font class='exdent'>
    <font class='funcname'>mexp </font>
    <font class='italic' color='purple'></font>
  </font><br>
<!-- open: 181, close: 180 --><font class="lisp">mexp</font><!-- open: 181, close: 181 --> <!-- MATCHED MATCHED MATCHED --> goes into a loop in which it reads forms and sequentially
expands them, printing out the result of each expansion.  It terminates
when it reads an atom (anything that is not a cons).  If you type
in a form which is not a macro form, there will be no expansions
and so it will not type anything out, but just prompt you for
another form.  This allows you to see what your macros are
expanding into, without actually evaluating the result of the expansion.
</div>

<div class='section' id='19.4'>19.4 Displacing Macros</div><p class='cindent' id='displacing-macro'><!-- displacing macros -->
	Every time the the evaluator sees a macro form, it must
call the macro to expand the form.  If this expansion always
happens the same way, then it is wasteful to expand the whole
form every time it is reached; why not just expand it once?
A macro is passed the macro form itself, and so it can change
the car and cdr of the form to something else by using <!-- open: 182, close: 181 --><font class="lisp">rplaca</font><!-- open: 182, close: 182 --> <!-- MATCHED MATCHED MATCHED -->
and <!-- open: 183, close: 182 --><font class="lisp">rplacd</font><!-- open: 183, close: 183 --> <!-- MATCHED MATCHED MATCHED -->!  This way the first time the macro is expanded,
the expansion will be put where the macro form used to be, and the
next time that form is seen, it will already be expanded.  A macro that
does this is called a <!-- open: 184, close: 183 --><font class="italic">displacing macro</font><!-- open: 184, close: 184 --> <!-- MATCHED MATCHED MATCHED -->, since it displaces
the macro form with its expansion.

	The major problem with this is that the Lisp form
gets changed by its evaluation.  If you were to write a program
which used such a macro, call <!-- open: 185, close: 184 --><font class="lisp">grindef</font><!-- open: 185, close: 185 --> <!-- MATCHED MATCHED MATCHED --> to look at it,
then run the program and call <!-- open: 186, close: 185 --><font class="lisp">grindef</font><!-- open: 186, close: 186 --> <!-- MATCHED MATCHED MATCHED --> again, you would
see the expanded macro the second time.  Presumably the reason
the macro is there at all is that it makes the program look nicer;
we would like to prevent the unnecessary expansions, but still let
<!-- open: 187, close: 186 --><font class="lisp">grindef</font><!-- open: 187, close: 187 --> <!-- MATCHED MATCHED MATCHED --> display the program in its more attractive form.
This is done with the function <!-- open: 188, close: 187 --><font class="lisp">displace</font><!-- open: 188, close: 188 --> <!-- MATCHED MATCHED MATCHED -->.

<div class='defun' id='displace'>
  <font class='exdent'>
    <font class='funcname'>displace </font>
    <font class='italic' color='purple'>form expansion</font>
  </font><br>
<!-- open: 189, close: 188 --><font class="italic">form</font><!-- open: 189, close: 189 --> <!-- MATCHED MATCHED MATCHED --> must be a list.
<!-- open: 190, close: 189 --><font class="lisp">displace</font><!-- open: 190, close: 190 --> <!-- MATCHED MATCHED MATCHED --> replaces the car and cdr of <!-- open: 191, close: 190 --><font class="italic">form</font><!-- open: 191, close: 191 --> <!-- MATCHED MATCHED MATCHED --> so
that it looks like:
<pre class='lisp'>
(si:displaced <!-- open: 192, close: 191 --><font class="italic">original-form</font><!-- open: 192, close: 192 --> <!-- MATCHED MATCHED MATCHED --> <!-- open: 193, close: 192 --><font class="italic">expansion</font><!-- open: 193, close: 193 --> <!-- MATCHED MATCHED MATCHED -->)
</pre>
<!-- open: 194, close: 193 --><font class="italic">original-form</font><!-- open: 194, close: 194 --> <!-- MATCHED MATCHED MATCHED --> is equal to <!-- open: 195, close: 194 --><font class="italic">form</font><!-- open: 195, close: 195 --> <!-- MATCHED MATCHED MATCHED --> but has a different
top-level cons so that the replacing mentioned above doesn't
affect it.  <!-- open: 196, close: 195 --><font class="lisp">si:displaced</font><!-- open: 196, close: 196 --> <!-- MATCHED MATCHED MATCHED --> is a macro, which returns
the caddr of its own macro form.  So when the <!-- open: 197, close: 196 --><font class="lisp">si:displaced</font><!-- open: 197, close: 197 --> <!-- MATCHED MATCHED MATCHED -->
form is given to the evaluator, it "expands" to <!-- open: 198, close: 197 --><font class="italic">expansion</font><!-- open: 198, close: 198 --> <!-- MATCHED MATCHED MATCHED -->.
<!-- open: 199, close: 198 --><font class="lisp">displace</font><!-- open: 199, close: 199 --> <!-- MATCHED MATCHED MATCHED --> returns <!-- open: 200, close: 199 --><font class="italic">expansion</font><!-- open: 200, close: 200 --> <!-- MATCHED MATCHED MATCHED -->.
</div>

	The grinder knows specially about <!-- open: 201, close: 200 --><font class="lisp">si:displaced</font><!-- open: 201, close: 201 --> <!-- MATCHED MATCHED MATCHED --> forms,
and will grind such a form as if it had seen the original-form
instead of the <!-- open: 202, close: 201 --><font class="lisp">si:displaced</font><!-- open: 202, close: 202 --> <!-- MATCHED MATCHED MATCHED --> form.

	So if we wanted to rewrite our <!-- open: 203, close: 202 --><font class="lisp">addone</font><!-- open: 203, close: 203 --> <!-- MATCHED MATCHED MATCHED --> macro as a displacing
macro, instead of writing
<pre class='lisp'>
(macro addone (x)
   (list 'plus '1 (cadr x)))
</pre>
we would write
<pre class='lisp'>
(macro addone (x)
   (displace x (list 'plus '1 (cadr x))))
</pre>

	Of course, we really want to use <!-- open: 204, close: 203 --><font class="lisp">defmacro</font><!-- open: 204, close: 204 --> <!-- MATCHED MATCHED MATCHED --> to define
most macros.  Since there is no way to get at the original macro form itself
from inside the body of a <!-- open: 205, close: 204 --><font class="lisp">defmacro</font><!-- open: 205, close: 205 --> <!-- MATCHED MATCHED MATCHED -->, another version of it is
provided:

<div class='defmac' id='defmacro-displace'><font class='exdent'><font class='funcname' id='defmacro-displace'>defmacro-displace</font><font class="italic"> Macro</font></br></font><!-- end font_exdent --><!-- open: 206, close: 205 --><font class="lisp">defmacro-displace</font><!-- open: 206, close: 206 --> <!-- MATCHED MATCHED MATCHED --> is just like <!-- open: 207, close: 206 --><font class="lisp">defmacro</font><!-- open: 207, close: 207 --> <!-- MATCHED MATCHED MATCHED --> except that
it defines a displacing macro, using the <!-- open: 208, close: 207 --><font class="lisp">displace</font><!-- open: 208, close: 208 --> <!-- MATCHED MATCHED MATCHED --> function.
</div>

	Now we can write the displacing version of <!-- open: 209, close: 208 --><font class="lisp">addone</font><!-- open: 209, close: 209 --> <!-- MATCHED MATCHED MATCHED --> as
<pre class='lisp'>
(defmacro-displace addone (form)
   (list 'plus '1 form))
</pre>
All we have changed in this example is the <!-- open: 210, close: 209 --><font class="lisp">defmacro</font><!-- open: 210, close: 210 --> <!-- MATCHED MATCHED MATCHED --> into
<!-- open: 211, close: 210 --><font class="lisp">defmacro-displace</font><!-- open: 211, close: 211 --> <!-- MATCHED MATCHED MATCHED -->.  <!-- open: 212, close: 211 --><font class="lisp">addone</font><!-- open: 212, close: 212 --> <!-- MATCHED MATCHED MATCHED --> is now a displacing macro.

<div class='section' id='19.5'>19.5 Advanced Features of Defmacro</div>(To be supplied.)

(The basic matter is that you can use <!-- open: 213, close: 212 --><font class="lisp">&amp;optional</font><!-- open: 213, close: 213 --> <!-- MATCHED MATCHED MATCHED --> and <!-- open: 214, close: 213 --><font class="lisp">&amp;rest</font><!-- open: 214, close: 214 --> <!-- MATCHED MATCHED MATCHED -->
with <!-- open: 215, close: 214 --><font class="lisp">defmacro</font><!-- open: 215, close: 215 --> <!-- MATCHED MATCHED MATCHED -->.  The interactions between <!-- open: 216, close: 215 --><font class="lisp">&amp;optional</font><!-- open: 216, close: 216 --> <!-- MATCHED MATCHED MATCHED -->'s initialization,
and the fact that the "lambda-list" in <!-- open: 217, close: 216 --><font class="lisp">defmacro</font><!-- open: 217, close: 217 --> <!-- MATCHED MATCHED MATCHED --> can be arbitrary
list structure are not clear.  If you need to use this feature, try it out.)

<div class='section' id='19.6'>19.6 Functions to Expand Macros</div>
	The following two functions are provided to allow
the user to control expansion of macros; they are often
useful for the writer of advanced macro systems.

<div class='defun' id='macroexpand-1'>
  <font class='exdent'>
    <font class='funcname'>macroexpand-1 </font>
    <font class='italic' color='purple'>form &optional compilerp</font>
  </font><br>
If <!-- open: 218, close: 217 --><font class="italic">form</font><!-- open: 218, close: 218 --> <!-- MATCHED MATCHED MATCHED --> is a macro form, this expands it (once)
and returns the expanded form.  Otherwise it just
returns <!-- open: 219, close: 218 --><font class="italic">form</font><!-- open: 219, close: 219 --> <!-- MATCHED MATCHED MATCHED -->.  If <!-- open: 220, close: 219 --><font class="lisp">compilerp</font><!-- open: 220, close: 220 --> <!-- MATCHED MATCHED MATCHED --> is <!-- open: 221, close: 220 --><font class="lisp">t</font><!-- open: 221, close: 221 --> <!-- MATCHED MATCHED MATCHED -->, <!-- open: 222, close: 221 --><font class="lisp">macroexpand-1</font><!-- open: 222, close: 222 --> <!-- MATCHED MATCHED MATCHED -->
will search the compiler's list of intenally defined macros
(<!-- open: 223, close: 222 --><font class="lisp">sys:macrolist</font><!-- open: 223, close: 223 --> <!-- MATCHED MATCHED MATCHED -->) for a definition, as well as the function cell
of the <!-- open: 224, close: 223 --><font class="italic">car</font><!-- open: 224, close: 224 --> <!-- MATCHED MATCHED MATCHED --> of <!-- open: 225, close: 224 --><font class="italic">form</font><!-- open: 225, close: 225 --> <!-- MATCHED MATCHED MATCHED -->.  <!-- open: 226, close: 225 --><font class="italic">compilerp</font><!-- open: 226, close: 226 --> <!-- MATCHED MATCHED MATCHED --> defaults to <!-- open: 227, close: 226 --><font class="lisp">nil</font><!-- open: 227, close: 227 --> <!-- MATCHED MATCHED MATCHED -->.
</div>

<div class='defun' id='macroexpand'>
  <font class='exdent'>
    <font class='funcname'>macroexpand </font>
    <font class='italic' color='purple'>form &optional compilerp</font>
  </font><br>
If <!-- open: 228, close: 227 --><font class="italic">form</font><!-- open: 228, close: 228 --> <!-- MATCHED MATCHED MATCHED --> is a macro form, this expands it repeatedly
until it is not a macro form, and returns the final expansion.
Otherwise, it just returns <!-- open: 229, close: 228 --><font class="italic">form</font><!-- open: 229, close: 229 --> <!-- MATCHED MATCHED MATCHED -->.  <!-- open: 230, close: 229 --><font class="italic">compilerp</font><!-- open: 230, close: 230 --> <!-- MATCHED MATCHED MATCHED --> has the
same meaning as in <!-- open: 231, close: 230 --><font class="lisp">macroexpand-1</font><!-- open: 231, close: 231 --> <!-- MATCHED MATCHED MATCHED -->.
</div>

<!-- eof -->
</body>
</html>

